package com.yatang.yiliao.app.utils;

import android.app.Dialog;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.Button;

/**
 * Created by YaTang Software on 2015/4/29.
 */
public class MyCountTimer extends CountDownTimer {


    private Button btn;
    private Dialog loadingDialog;


    public MyCountTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    public void setBtn(Button btn) {
        this.btn = btn;
    }

    public void setLoadingDialog(Dialog loadingDialog) {
        this.loadingDialog = loadingDialog;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (btn != null) {
            btn.setBackgroundColor(Color.GRAY);
            btn.setClickable(false);
            btn.setText(millisUntilFinished / 1000 + "s重新发送");
        }
    }

    @Override
    public void onFinish() {
        if (btn != null) {
            btn.setText("获取验证码");
            btn.setClickable(true);
            btn.setBackgroundColor(Color.parseColor("#3fa0ff"));
        }
        if (loadingDialog != null){
            loadingDialog.dismiss();
        }
    }
}
